package spzx.controller;

import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import spzx.service.BrandService;

import java.util.List;

@RestController
@RequestMapping("admin/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    /**
     * 根据三级目录分类id查询品牌
     * @param category3Id
     * @return
     */
    @GetMapping("findByCategory3Id/{category3Id}")
    public Result findByCategory3Id(@PathVariable Long category3Id) {
        List<Brand> list = brandService.findByCategory3Id(category3Id);
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }



    @GetMapping("findAll")
    public Result findAll() {
        List<Brand> list = brandService.findAll();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/addBrand")
    public Result addBrand(@RequestBody Brand brand) {
        brandService.addBrand(brand);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/updateBrand")
    public Result updateBrand(@RequestBody Brand brand) {
        brandService.updateBrand(brand);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/deleteBrand/{id}")
    public Result deleteBrand(@PathVariable Long id) {
        brandService.deleteBrand(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/getBrand/{pageNum}/{pageSize}")
    public Result getBrand(@PathVariable Integer pageNum, @PathVariable Integer pageSize) {
        PageInfo pageInfo = brandService.getBrand(pageNum, pageSize);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }
}
